package top.ucat.x.service.sso.server.service.provider;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.codehaus.jackson.map.Serializers;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import top.ucat.box.cloud.common.exception.BaseException;
import top.ucat.x.sso.service.provider.LoginService;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

@Service
public class LoginServiceImpl implements LoginService {

    @Reference
    private top.ucat.box.starter.oauth.common.service.LoginService loginService;

    @Override
    public OAuth2AccessToken loginByUsernameAndPassword(String username, String password) throws HttpRequestMethodNotSupportedException {        //获取token
        if (StringUtils.isBlank(username)) {
            throw new BaseException("用户名不能为空", 400);
        }
        if (StringUtils.isBlank(password)) {
            throw new BaseException("用户名不能为空", 400);
        }

        OAuth2AccessToken token = loginService.usernamePasswordAuthenticationToken(username
                , password, "management", "client", "secret");
        return token;
    }


}
